<html>
<head><meta charset="utf-8"><title>How does `repr(simd)` really work? · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html">How does `repr(simd)` really work?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="170773764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170773764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170773764">(Jul 13 2019 at 04:45)</a>:</h4>
<ul>
<li>Is there a guarantee on exactly how <code>repr(simd)</code> interacts with things like transmutes and such?</li>
<li>Is it "opaque" like <code>repr(rust)</code> or "just bits arranged a particular way" like <code>repr(C)</code>?</li>
<li>Is a <code>__m128</code> expected to be transmute-compatible with <code>u128</code> and <code>[f32;4]</code> and so on?</li>
<li>Are we assured by anything that the ordering of the lanes has a particular ordering compared to the indexes when it's transmuted into an array?</li>
</ul>



<a name="170779675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170779675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170779675">(Jul 13 2019 at 07:46)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="132920">@gnzlbg</span></p>



<a name="170779678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170779678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170779678">(Jul 13 2019 at 07:46)</a>:</h4>
<p>but also <span class="user-mention" data-user-id="224471">@Lokathor</span> have you read <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/packed-simd-vectors.md" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/packed-simd-vectors.md">https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/packed-simd-vectors.md</a> ?</p>



<a name="170779681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170779681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170779681">(Jul 13 2019 at 07:47)</a>:</h4>
<p>or I guess <a href="https://rust-lang.github.io/unsafe-code-guidelines/layout/packed-simd-vectors.html" target="_blank" title="https://rust-lang.github.io/unsafe-code-guidelines/layout/packed-simd-vectors.html">https://rust-lang.github.io/unsafe-code-guidelines/layout/packed-simd-vectors.html</a> is a better location</p>



<a name="170779684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170779684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170779684">(Jul 13 2019 at 07:47)</a>:</h4>
<p>some of these questions seem like they would be answered there</p>



<a name="170780085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170780085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170780085">(Jul 13 2019 at 08:00)</a>:</h4>
<p>I think all questions are answered there</p>



<a name="170781515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170781515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170781515">(Jul 13 2019 at 08:45)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> if you have further questions or something is not answered there feel free to ping me or open an issue</p>



<a name="170806576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170806576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170806576">(Jul 13 2019 at 21:51)</a>:</h4>
<p>Oh, right, of course. I somehow temporarily forgot that the book already has some content in it.</p>
<p>Okay, having read that and also having played around with it a bit in the playground, I'm going to conclude that we're in a good place for now, and then I'll add sanity tests to my crate to make sure that things stay good, and also subscribe to issue <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/36" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/36">https://github.com/rust-lang/unsafe-code-guidelines/issues/36</a> in case of updates.</p>



<a name="170807954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170807954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170807954">(Jul 13 2019 at 22:37)</a>:</h4>
<p>It appears that <code>miri</code> falls down when I try to run my basic sanity tests through it, <a href="https://pastebin.com/mjiVZuRp" target="_blank" title="https://pastebin.com/mjiVZuRp">https://pastebin.com/mjiVZuRp</a> (test code was <a href="https://gist.github.com/rust-play/c97f79a6c5ee81b82d044349cd267acb" target="_blank" title="https://gist.github.com/rust-play/c97f79a6c5ee81b82d044349cd267acb">https://gist.github.com/rust-play/c97f79a6c5ee81b82d044349cd267acb</a>)</p>
<p>I don't know if this is <code>miri</code> just not knowing what to do or what, but it's pointing the finger at stdimd, which I trust to have gotten the <code>x86_64</code> stuff correct.</p>



<a name="170808679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170808679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170808679">(Jul 13 2019 at 23:04)</a>:</h4>
<p>Ah, yeah, <code>miri</code> just isn't smart enough to handle this yet I guess. From the README</p>
<blockquote>
<p>Miri runs the program as a platform-independent interpreter, so the program has no access to any platform-specific APIs or FFI. A few APIs have been implemented (such as printing to stdout) but most have not: for example, Miri currently does not support concurrency, or networking, or file system access, or gathering entropy from the system.</p>
</blockquote>



<a name="170823350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823350">(Jul 14 2019 at 07:30)</a>:</h4>
<p>Yeah I should add SIMD to that list</p>



<a name="170823353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823353">(Jul 14 2019 at 07:30)</a>:</h4>
<p>the problem with SIMD is that it consists of hundreds of intrinsics (thousands really but I guess not all of them are important)</p>



<a name="170823354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823354">(Jul 14 2019 at 07:30)</a>:</h4>
<p>and they would have have to be implemented manually in Miri...</p>



<a name="170823361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823361">(Jul 14 2019 at 07:31)</a>:</h4>
<p>maybe there's a way to be smarter about them, by "parsing" the name of the intrinsic or so</p>



<a name="170823362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823362">(Jul 14 2019 at 07:31)</a>:</h4>
<p>but generally it's a lot of work and nobody has taken that on yet</p>



<a name="170823403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823403">(Jul 14 2019 at 07:32)</a>:</h4>
<p>However, the error is curious:</p>
<div class="codehilite"><pre><span></span>Miri evaluation error: tried to call a function with ABI RustIntrinsic using caller ABI PlatformIntrinsic
</pre></div>


<p><span class="user-mention" data-user-id="119009">@eddyb</span> <span class="user-mention" data-user-id="132920">@gnzlbg</span> is an ABI mismatch like that expected for SIMD?</p>



<a name="170823566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823566">(Jul 14 2019 at 07:39)</a>:</h4>
<p>well, kind of</p>



<a name="170823571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823571">(Jul 14 2019 at 07:39)</a>:</h4>
<p>many SIMD intrinsics end up calling a platform intrinsic</p>



<a name="170823612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823612">(Jul 14 2019 at 07:40)</a>:</h4>
<p>let me get you what's probably the offending code</p>



<a name="170823617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823617">(Jul 14 2019 at 07:40)</a>:</h4>
<p>miri would need to at least support all of these: <a href="https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/simd_llvm.rs#L5" target="_blank" title="https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/simd_llvm.rs#L5">https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/simd_llvm.rs#L5</a></p>



<a name="170823623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823623">(Jul 14 2019 at 07:41)</a>:</h4>
<p>note that the ABI of these is PlatformIntrinsic</p>



<a name="170823624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170823624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170823624">(Jul 14 2019 at 07:41)</a>:</h4>
<p>I don't think that miri should support more than these, at least not initially</p>



<a name="170824031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170824031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170824031">(Jul 14 2019 at 07:54)</a>:</h4>
<p>Im not even talking about implementing the intrinsic</p>



<a name="170824032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170824032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170824032">(Jul 14 2019 at 07:54)</a>:</h4>
<p>usually its an error if the ABI that the caller and callee used are not the same</p>



<a name="170824042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170824042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170824042">(Jul 14 2019 at 07:55)</a>:</h4>
<p>this is the insta-UB kind of error</p>



<a name="170824049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170824049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170824049">(Jul 14 2019 at 07:55)</a>:</h4>
<p>but here it seems okay? what is the difference between the RustIntrinsic and PlatformIntrinsic call ABIs?</p>



<a name="170824092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170824092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170824092">(Jul 14 2019 at 07:56)</a>:</h4>
<p>(if e.g. one ABI was <code>C</code> and the other <code>Rust</code>, that would definitely be UB)</p>



<a name="170825523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170825523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170825523">(Jul 14 2019 at 08:41)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> where is the ABI difference? - the intrinsics are PlatformIntrinsic</p>



<a name="170825530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170825530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170825530">(Jul 14 2019 at 08:42)</a>:</h4>
<p>If you declare the intrinsics as <code>extern "C"</code> and call them, that is UB - you need to declare them as "platform-intrinsic"</p>



<a name="170825576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170825576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170825576">(Jul 14 2019 at 08:42)</a>:</h4>
<p>AFAICT, they are declared as "platform-intrinsic" everywhere in all Rust code</p>



<a name="170825595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170825595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170825595">(Jul 14 2019 at 08:43)</a>:</h4>
<blockquote>
<p>usually its an error if the ABI that the caller and callee used are not the same</p>
</blockquote>
<p>I suppose that by this you mean that the ABI of a declaration must match the ABI of the definition</p>



<a name="170825599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170825599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170825599">(Jul 14 2019 at 08:43)</a>:</h4>
<p>It is possible to call an <code>extern "C"</code> function from an <code>extern "Rust"</code> function</p>



<a name="170825640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170825640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170825640">(Jul 14 2019 at 08:44)</a>:</h4>
<p>what cannot be done is call an <code>extern "Rust"</code> function via a declaration that says this function is <code>extern "C"</code></p>



<a name="170826318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170826318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170826318">(Jul 14 2019 at 09:07)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> these ABIs are just a hack, RustCall and RustIntrinsic and PlatformIntrinsic are all Rust</p>



<a name="170826365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170826365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170826365">(Jul 14 2019 at 09:08)</a>:</h4>
<p>someone needs to go and clean that mess up and it's not high priority enough to actually happen :(</p>



<a name="170827629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827629">(Jul 14 2019 at 09:54)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> I see, so there's no "good" reason for these to be separate ABIs?</p>



<a name="170827634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827634">(Jul 14 2019 at 09:54)</a>:</h4>
<p>yeah it's just used to signal that something is an intrinsic</p>



<a name="170827635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827635">(Jul 14 2019 at 09:54)</a>:</h4>
<blockquote>
<p>what cannot be done is call an <code>extern "Rust"</code> function via a declaration that says this function is <code>extern "C"</code></p>
</blockquote>
<p>yes. every fn call has two ABIs: the ABI the caller assumes this fn has, and the ABI the fn really has. the error says that they are not the same.</p>



<a name="170827641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827641">(Jul 14 2019 at 09:55)</a>:</h4>
<p>this is an error similar in kind to "you called a 5-param function with 3 params"</p>



<a name="170827743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827743">(Jul 14 2019 at 09:59)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> <a href="https://github.com/rust-lang/rust/pull/62674" target="_blank" title="https://github.com/rust-lang/rust/pull/62674">https://github.com/rust-lang/rust/pull/62674</a></p>



<a name="170827869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827869">(Jul 14 2019 at 10:03)</a>:</h4>
<p>once that lands., the error message should be better for when a SIMD intrinsic is used</p>



<a name="170827874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827874">(Jul 14 2019 at 10:03)</a>:</h4>
<p>should be something like "intrinsic not implemented: simd_add"</p>



<a name="170827915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827915">(Jul 14 2019 at 10:04)</a>:</h4>
<p>and then someone can go in and implement all of them :P</p>



<a name="170827922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827922">(Jul 14 2019 at 10:04)</a>:</h4>
<p>you can get the vector shape from <code>layout.abi</code> being <code>Abi::Vector</code> and then compute element offsets like an array</p>



<a name="170827932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170827932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170827932">(Jul 14 2019 at 10:05)</a>:</h4>
<p>like, this would be a fun project IMO, at least for the platform-independent ones (like <code>simd_add</code>)</p>



<a name="170828152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170828152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170828152">(Jul 14 2019 at 10:12)</a>:</h4>
<p>FWIW I'm actually working on making <code>repr(simd)</code> types support an array right now</p>



<a name="170828162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170828162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170828162">(Jul 14 2019 at 10:13)</a>:</h4>
<p>I just discovered that we also support, e.g., <code>#[repr(simd)] struct Rgba { r: f32, g: f32, b: f32, a: f32 }</code>, as well as <code>#[repr(simd)]</code> types of non-power-of-two sizes</p>



<a name="170913346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170913346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170913346">(Jul 15 2019 at 17:24)</a>:</h4>
<p>Now that you mention it, the "Layout of packed SIMD vectors" page in the UCG says that the Packed SIMD types <em>are</em> <code>#[repr(simd)]</code>with an example definition and says that they always have a power of two number of lanes, <em>but it doesn't say that you can't apply <code>repr(simd)</code> to other things</em>.</p>



<a name="170913478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170913478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170913478">(Jul 15 2019 at 17:25)</a>:</h4>
<p>You can't apply <code>repr(simd)</code> to anything, only the compiler can do that, so the point is a bit moot :P</p>



<a name="170913540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170913540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170913540">(Jul 15 2019 at 17:26)</a>:</h4>
<p>you just said you put it on a RGBA struct :P</p>



<a name="170974795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How%20does%20%60repr%28simd%29%60%20really%20work%3F/near/170974795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/How.20does.20.60repr(simd).60.20really.20work.3F.html#170974795">(Jul 16 2019 at 11:03)</a>:</h4>
<p>in the compiler :P</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>